#ifndef _LIST_H
#define _LIST_H

#include <stdarg.h>

#define queue_enqueue(zz, p) \
   list_insert(zz, 0, p)

#define queue_dequeue(zz) \
  list_remove_node(zz, zz->head)

typedef struct list_node_s
{
  struct list_node_s *next;
  struct list_node_s *previous;
  void *item;
} list_node;

typedef struct list_s
{
  list_node *head;
  list_node *tail;
  long count;
} list;

list *list_new(void);
void list_delete(list *, void (*item_free_f)(void *));
void list_free(list *);
void list_freei(list *, void (*item_free_f)(void *));
void list_insert(list *, list_node *pnode, void *pitem);
void *list_remove(list *, void *pitem);
void *list_traverse(list *, int (*item_f)(void *, va_list), ...);
int list_dump(list *);
void *list_first(list *);
void *list_last(list *);
void *list_at(list *, int num);
list_node *list_find(list *, void *pitem);
void *list_remove_node(list *, list_node *p);

#endif /* _LIST_H */
